package com.xcc.core.spder.test.langchao;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JOptionPane;


import com.xcc.core.spder.thread.XinlangClient;
import com.xcc.core.util.DataUtil;

public class SpderLangchao {
// 300035.sz 300568.sz  002415.sz  sz002415
    /**
     *〈简述〉
     *〈详细描述〉
     * @author Dell
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        XinlangClient mClient =new XinlangClient("sz002415");
        Calendar calendar = Calendar.getInstance();  
        calendar.set(Calendar.HOUR_OF_DAY, 9); // 控制时  
        calendar.set(Calendar.MINUTE,15);       // 控制分  
        calendar.set(Calendar.SECOND, 0);       // 控制秒  
        Date time = calendar.getTime();         // 得出执行任务的时间,此处为今天的9：00：00  

        Timer timer = new Timer();  
        timer.scheduleAtFixedRate(new TimerTask() {  
            public void run() {  
                 try {
                    if (DataUtil.dayForWeek() == 6  ||DataUtil.dayForWeek()==7  ) {
                         return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                while(true) {
                   
                    try {
                        if( new Date().after(DataUtil.customeDate(15, 0, 0))) {
                             break;
                        }
                        if( new Date().before(DataUtil.customeDate(9, 15, 0))) {
                          break;
                        }
                    
                       long sleepTime= DataUtil.customeDate(13, 30, 0).getTime()-  new Date().getTime() ;
                       long shangwu= DataUtil.customeDate(11, 30, 0).getTime()-  new Date().getTime() ;

                       if(sleepTime>0&&shangwu<0) {
                           System.out.println(sleepTime);
                            Thread.sleep(sleepTime);
                        }
                        SimpleDateFormat dateFormat=new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String langchao=mClient.excetor("sz002415");
                        String  tianqi=mClient.excetor("sz002155");
                       
                        if(Double.parseDouble(langchao)>60||Double.parseDouble(tianqi)>=60) {
                            JOptionPane.showMessageDialog(null, "卖出浪潮", "股票", JOptionPane.PLAIN_MESSAGE);
                            break;
                        }else {
                            Thread.sleep(5000);
                            double valueLongchao= Double.parseDouble(langchao);
                            double valueLongchaoChenben= Double.parseDouble("57.32");
                            double valuetianqi= Double.parseDouble(tianqi);
                            double valuetianqiChenben= Double.parseDouble("11.44");

                            System.out.println(
                                dateFormat.format(new Date())+" "+outFormat("海康",valueLongchao,valueLongchaoChenben,100)+" "
                                + outFormat("湖南黄金",valuetianqi,valuetianqiChenben,500)
                                );
                        } 
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    } 
                }
            }  
        }, time, 1000  * 60 * 60 * 24   );// 这里设定将延时每天固定执行  

    }

    
    
    public static String outFormat(String name,double value,double chengben,int num) {
     return    name+":"+value+
             ":"+chengben+
             ":"+ ((value-chengben)*num+"").substring(0, 5)+
              ":"+ ((value-chengben)/chengben*100+"").substring(0, 5)+"%";
    }
    
   
}
